<template>
  <div>
    <el-checkbox-group v-model="roleIds">
      <el-checkbox v-for="item in data" :key="item.id" :label="item.id">{{ item.name }}</el-checkbox>
    </el-checkbox-group>
    <div style="margin-top: 20px; text-align: right">
      <el-button type="primary" @click="success">确定</el-button>
      <el-button @click="$emit('update:dialogTableVisible1', false)">取消</el-button>
    </div>
  </div>
</template>

<script>
import { getRoleManagement } from '@/api/setting'
import { getUserInfo, setAssignRoles } from '@/api/user'

export default {
  name: 'VueAdminTemplateMasterRoledialog',
  props: {
    dialogTableVisible1: {
      type: Boolean
    }
  },
  data() {
    return {
      roleIds: [],
      data: [],
      defaultProps: {
        children: 'children',
        label: 'name'
      },
      id: ''
    }
  },

  created() {
    this.getRoleManagement()
  },

  methods: {

    // 获取员工基本信息
    async getRoleManagement() {
      const res = await getRoleManagement({ page: 1, pagesize: 1000 })
      if (res.code === 10000) {
        this.data = res.data.rows
        this.getUserInfo()
      }
    },
    // 获取员工基本信息
    async getUserInfo() {
      const res = await getUserInfo(this.id)
      if (res.code === 10000) {
        this.roleIds = res.data.roleIds
      }
    },

    // 确定
    async success() {
      const res = await setAssignRoles({
        id: this.id,
        roleIds: this.roleIds
      })
      if (res.code === 10000) {
        this.$emit('update:dialogTableVisible1', false)
        this.$parent.$parent.getUserList()
      }
    }
  }
}
</script>

<style lang="scss" scoped>

</style>
